using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Colorprj.Challan;
using Colorprj.Common;
using Colorprj.Invoice ;
namespace Colorprj
{
    public partial class frmrptInvoice : Form
    {
        InvoiceManager im = new InvoiceManager(); 
        public frmrptInvoice()
        {
            InitializeComponent();
        }

        //private void btnShow_Click(object sender, EventArgs e)
        //{
        //    showReport(Convert.ToInt16(textBox1.Text) );
        //}
        private void showReport(int InvoiceId)
        {

            ReportDocument cryRpt = new Report.rptInvoice()  ;
            //string appPath = Path.GetDirectoryName(Application.ExecutablePath);
            //cryRpt.Load(Utility.GetInvRptLocation());

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();


            ParameterValues crParameterValues1 = new ParameterValues();
            ParameterFieldDefinition crParameterFieldDefinition1;
            ParameterDiscreteValue crParameterDiscreteValue1 = new ParameterDiscreteValue();


            ParameterValues crParameterValuesAdd1 = new ParameterValues();
            ParameterFieldDefinition crParameterFieldDefinitionAdd1;
            ParameterDiscreteValue crParameterDiscreteValueAdd1 = new ParameterDiscreteValue();



            ParameterValues crParameterValuesAdd2 = new ParameterValues();
            ParameterFieldDefinition crParameterFieldDefinitionAdd2;
            ParameterDiscreteValue crParameterDiscreteValueAdd2 = new ParameterDiscreteValue();


            ParameterValues crParameterValuesEmail = new ParameterValues();
            ParameterFieldDefinition crParameterFieldDefinitionEmail;
            ParameterDiscreteValue crParameterDiscreteValueEmail = new ParameterDiscreteValue();

            ParameterValues crParameterValuesPhone = new ParameterValues();
            ParameterFieldDefinition crParameterFieldDefinitionPhone;
            ParameterDiscreteValue crParameterDiscreteValuePhone = new ParameterDiscreteValue();

            ParameterValues crParameterValuesTIN = new ParameterValues();
            ParameterFieldDefinition crParameterFieldDefinitionTIN;
            ParameterDiscreteValue crParameterDiscreteValueTIN = new ParameterDiscreteValue();

            ParameterValues crParameterValuesCST = new ParameterValues();
            ParameterFieldDefinition crParameterFieldDefinitionCST;
            ParameterDiscreteValue crParameterDiscreteValueCST = new ParameterDiscreteValue();


            crParameterDiscreteValue.Value = InvoiceId;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["InvNo"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;


            crParameterDiscreteValue1.Value = Globalclass.CompanyName; ;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition1 = crParameterFieldDefinitions["cName"];
            crParameterValues1 = crParameterFieldDefinition1.CurrentValues;


            crParameterDiscreteValueAdd1.Value = Globalclass.Address1;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinitionAdd1 = crParameterFieldDefinitions["cAdd1"];
            crParameterValuesAdd1 = crParameterFieldDefinition1.CurrentValues;

            crParameterDiscreteValueAdd2.Value = Globalclass.Address2;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinitionAdd2 = crParameterFieldDefinitions["cAdd2"];
            crParameterValuesAdd2 = crParameterFieldDefinitionAdd2.CurrentValues;

            crParameterDiscreteValueEmail.Value = Globalclass.Email;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinitionEmail = crParameterFieldDefinitions["cEmail"];
            crParameterValuesEmail = crParameterFieldDefinitionEmail.CurrentValues;

            crParameterDiscreteValuePhone.Value = Globalclass.PhoneNo;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinitionPhone = crParameterFieldDefinitions["cPhone"];
            crParameterValuesPhone = crParameterFieldDefinitionPhone.CurrentValues;


            crParameterDiscreteValueTIN.Value = Globalclass.TinNo;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinitionTIN = crParameterFieldDefinitions["cTIN"];
            crParameterValuesTIN = crParameterFieldDefinitionTIN.CurrentValues;

            crParameterDiscreteValueCST.Value = Globalclass.CstNo;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinitionCST = crParameterFieldDefinitions["cCST"];
            crParameterValuesCST = crParameterFieldDefinitionTIN.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);


            crParameterValues1.Add(crParameterDiscreteValue1);
            crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1);


            crParameterValuesAdd1.Add(crParameterDiscreteValueAdd1);
            crParameterFieldDefinitionAdd1.ApplyCurrentValues(crParameterValuesAdd1);

            crParameterValuesAdd2.Add(crParameterDiscreteValueAdd2);
            crParameterFieldDefinitionAdd2.ApplyCurrentValues(crParameterValuesAdd2);


            crParameterValuesEmail.Add(crParameterDiscreteValueEmail);
            crParameterFieldDefinitionEmail.ApplyCurrentValues(crParameterValuesEmail);

            crParameterValuesPhone.Add(crParameterDiscreteValuePhone);
            crParameterFieldDefinitionPhone.ApplyCurrentValues(crParameterValuesPhone);

            crParameterValuesTIN.Add(crParameterDiscreteValueTIN);
            crParameterFieldDefinitionTIN.ApplyCurrentValues(crParameterValuesTIN);

            crParameterValuesCST.Add(crParameterDiscreteValueCST);
            crParameterFieldDefinitionCST.ApplyCurrentValues(crParameterValuesCST);

            cryRpt.DataSourceConnections[0].SetConnection(Globalclass.DsnName, Globalclass.DbName, "atul", "vikas");
            cryRpt.SetDatabaseLogon("atul", "vikas", Globalclass.DsnName, Globalclass.DbName  , false);
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();

        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {

        }

        private void tsBtnShow_Click(object sender, EventArgs e)
        {
            if (cboInvoiceNo.ComboBox.SelectedIndex == -1)
            {
                MessageBox.Show("Please select Invoce No");  
            }
            else
            {
                showReport(Convert.ToInt16(cboInvoiceNo.ComboBox.SelectedValue));
            }
        }

        private void frmrptInvoice_Load(object sender, EventArgs e)
        {
            cboInvoiceNo.ComboBox.DataSource = im.getAllInvoices().Tables[0] ;
            cboInvoiceNo.ComboBox.DisplayMember = "invoiceNo";
            cboInvoiceNo.ComboBox.ValueMember  = "invoiceNo";
        }
    }
}